<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
  <form>
    <!-- 计数器 -->

  
   <input type="button" onclick="doTimer()" value="开始计数">
   <input id="demo" type="text">
   <input type="button" onclick="stopCount()" value="停止计数">
  </form>
  <p>单击按钮，输入将从0开始一直计数</p>
   

   
  
    <script>
      var time_is_on=0;
      var c=0;
      var t;
      function timeCount() {
        document.getElementById("demo").value = c;
        c +=1;
        t = setTimeout("timeCount()",1000);

      }
      function stopCount() {
        clearTimeout(t);
        time_is_on=0;
      }
      
      function doTimer() {
        if(!time_is_on){
          time_is_on = 1;
          timeCount();
        }
        
      }

    
    </script>
</body>


</html>